//
//  JXHUserAcccountTool.swift
//  JXHSinaWeiBo
//
//  Created by juxiaohui on 16/10/20.
//  Copyright © 2016年 juxiaohui. All rights reserved.
//

import UIKit

class JXHUserAcccountTool {
    
    static let shareInstance : JXHUserAcccountTool = JXHUserAcccountTool()
    
    // MARK: - 计算属性
    
    var accontPath : String {
        let accontPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last!
       return (accontPath as NSString).appendingPathComponent("accont.plist")
    }
    
    var accont : JXHUserAccontModel?
    
    
    
    // MARK: - 重写init
    init() {
     
        // 从沙盒中读取归档信息
        accont = NSKeyedUnarchiver.unarchiveObject(withFile: accontPath) as? JXHUserAccontModel
    }
    
    
    func isLogin() -> Bool {
        
        if accont == nil {
            return false
        }
        return accont?.expiresDate?.compare(Date()) == ComparisonResult.orderedDescending
    }
}
